<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/node_modules/axios/dist/axios.min.js"></script>
    <title>Document</title>
</head>

<body>
    <button></button>
    <button></button>
    <script>
        const controller = new AbortController();
        let btn = document.querySelectorAll('button');
        btn[0].onclick = function () {
            axios({
                signal: controller.signal,
                //请求类型
                method: 'GET',
                url: 'http://localhost:3000/posts'

            }).then(response => {
                console.log(response);
            });

        }
        btn[1].onclick = function () {
            controller.abort();
        }
    </script>
</body>

</html>